# -*- coding: utf-8 -*-

from w.blocks.containers.form import Form as FormContainer
from w.blocks.block import BaseBlock as Block
from w.blocks.button import OKButton, ClearButton, BaseButton

class Error(Exception):
    pass

class Form(FormContainer, Block):
    scriptFiles = ['w/blocks/form.js']+BaseButton.scriptFiles

    def __init__(self, content, name, clearButton='', okButton=None, *argv, **kwargv):
        clearButton = clearButton if clearButton!=None else ClearButton(content='Clear')
        okButton = okButton if okButton!=None else OKButton(content='OK')
        
        FormContainer.__init__(self, content, name, okButton=okButton, clearButton=clearButton, *argv, **kwargv)
        Block.__init__(self, *argv, **kwargv)
        
        self.tag.html.id = 'dom%s'%self.blockID

    def jsCode(self):
        res = ''
        if self.okButton:
            res += self.okButton.jsCode()
        if self.clearButton:
            res += self.clearButton.jsCode()
            
        if res:
            return '%s\n%s'%(Block.jsCode(self), res)
        return Block.jsCode(self)

    def make(self, content=[]):
        return Block.make(self, FormContainer.make(self, content))

